package com.burns.java.base;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;

public class ByteToCharTest {
    public  static  void main(String[] args) throws Exception {

        byte2CharTest();
    }


    public static void byte2CharTest() throws Exception{
        String s1 = "这";
        byte[] b1 = s1.getBytes("UTF-8");
        String s2 = "是";
        byte[] b2= s2.getBytes("UTF-8");
        String s3 = "一";
        byte[] b3 = s3.getBytes("UTF-8");
        String s4 = "段";
        byte[] b4 = s4.getBytes("UTF-8");
        String s5 = "中";
        byte[] b5 = s5.getBytes("UTF-8");
        String s6 = "文";
        byte[] b6 = s6.getBytes("UTF-8");
        String s7 = "字";
        byte[] b7 = s7.getBytes("UTF-8");
        String s8 = "符";
        byte[] b8 = s8.getBytes("UTF-8");
        String s9 = "串";
        byte[] b9 = s9.getBytes("UTF-8");
        String s10 = "1";
        byte[] b10 = s10.getBytes("UTF-8");
        String s11 = "a";
        byte[] b11 = s11.getBytes("UTF-8");
        String s = "这是一段中文字符串";
        byte[] b = s.getBytes("UTF-8");

        String ss = new String(b,"UTF-8");

        Charset charset = Charset.forName("UTF-8");
        ByteBuffer byteBuffer = charset.encode(s);
        CharBuffer charBuffer = charset.decode(byteBuffer);

        ByteBuffer heapByteBuffer = ByteBuffer.allocate(1024);
        char c='c';
        ByteBuffer byteBuffer1 = heapByteBuffer.putChar(c);
    }
}
